-
Notifications
You must be signed in to change notification settings - Fork 52
feat: add context change listeners for flag subscriptions #1281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for the PoC, @jonathannorris! The first thing coming to my mind regarding the proposal is that it is reacting to variable value changes caused by context changes, but not to the ones caused by the provider backend (i.e. when an admin flips a flag or when a scheduled feature activation is due). This second one is a much more fundamental change, because providers also need to implement some server-to-client communication or polling to their own backends, but this is the way to support on-the-fly variable updates. You and your colleagues implemented this in the DevCycle Android SDK with SSE, that's inspired me to open the referenced ticket in the spec repo: So regarding the proposed API: as the author of the |
|
Hey @jonathannorris, as discusses in the community meeting and described by @bencehornak, I think we would not only want to react to
This makes sense to me @bencehornak. But we also have examples where we only want to react to one type of event.
@bencehornak I do not see this as a problem, this is the case today too. If providers have a way to emit config changes they get emitted, otherwise the event will simply never trigger. |
2a84c0f to
ed511e3
Compare
Signed-off-by: Jonathan Norris <jonathan@taplytics.com>
…level subscriptions Signed-off-by: Jonathan Norris <jonathan@taplytics.com>
…change subscriptions - Rename context-specific methods to generic names (onContextChanged -> onChanged, etc.) - Add FlagChangeSubscriptionOptions with updateOnContextChanged and updateOnConfigurationChanged - Support both ContextChanged and ConfigurationChanged events by default - Update tests to properly await async setContext and fix spread operator issues with class instances - Fix hooks test to compare evaluation details by property values instead of object reference Signed-off-by: Jonathan Norris <jonathan@taplytics.com>
0672864 to
c2de1b7
Compare
Signed-off-by: Jonathan Norris <jonathan@taplytics.com>
Add Context Change Listeners for Flag Subscriptions - Proposal
Overview
Implements context change listeners for the web SDK, addressing open-feature/spec#346. Provides a type-safe way to subscribe to flag value updates when evaluation context changes.
Problem
The current Events API requires significant boilerplate to track individual flag values. This PR adds a convenient API allowing developers to subscribe directly to flag changes with minimal code.
Solution
Two approaches for subscribing to context changes are implemented as examples for discussion:
1. EvaluationDetails Subscriptions
Enhanced
EvaluationDetailsobjects returned from evaluation methods include anonContextChangedmethod. The callback is invoked whenever the context changes.2. Client-Level Subscriptions
Type-specific methods directly on the client for subscribing to context changes. Performs an initial flag evaluation and invokes the callback immediately, then again whenever the context changes.
Implementation
EvaluationDetailsWithSubscription- WrapsEvaluationDetailswith subscription capabilityContextChangeSubscriptionsinterface - Groups subscription methodsevaluateWithSubscriptionhelper - DRY wrapper for evaluation resultsImportant: Providers do NOT need to implement
ContextChangedevents. The SDK automatically emits these events after context changes viasetContext(), making this implementation reliable and provider-agnostic.Handler Management: Uses closure-based approach consistent with existing SDK patterns. A WeakMap-based subscription registry was considered for subscription introspection/bulk operations but would diverge from current patterns and add complexity.
Usage Example
Related Issues
Addresses open-feature/spec#346